package com.qf.flash.mvp.presenter;

import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.PlayConditinoResponse;
import com.qf.flash.model.ScriptRoomBean;
import com.qf.flash.mvp.contract.ScriptContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.sharedpreferences.SavePermanentSharePrefs;
import com.qf.flashlib.sharedpreferences.SharePrefConstants;
import com.qf.flashlib.util.RxUtils;

import java.util.HashMap;
import java.util.List;

/**
 * 创建日期：2020/3/8 on 10:28
 * 描述:
 * 作者:戴旭东
 */
public class ScriptPrensenter extends BasePresenter<ScriptContract.View> implements ScriptContract.Presenter {
    @Override
    public void getPlayList(HashMap<String, Object> map) {
        String areaId = SavePermanentSharePrefs.getInstance().getDataString(SharePrefConstants.AREA_ID);
        map.put("areaId", areaId);
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
        .PLAY_LIST(map)
                .compose(RxUtils.<List<ScriptRoomBean>>handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<ScriptRoomBean>>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<List<ScriptRoomBean>> scriptRoom) {
                        mRootView.setPlayListData(scriptRoom.getData(), scriptRoom.getTotalPage());
                    }
                })
        );
    }

    @Override
    public void getShopPlayList(HashMap<String, Object> map) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SHOP_PLAY_LIST(map)
                .compose(RxUtils.<List<ScriptRoomBean>>handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<ScriptRoomBean>>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<List<ScriptRoomBean>> scriptRoom) {
                        mRootView.setPlayListData(scriptRoom.getData(), scriptRoom.getTotalPage());
                    }
                })
        );
    }

    @Override
    public void getConditions(String templateId, String isShop) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .PLAY_SEARCHES(templateId, isShop)
                .compose(RxUtils.<PlayConditinoResponse>handleResult())
                .compose(RxUtils.<PlayConditinoResponse>io_main())
                .subscribeWith(new BaseSubscriber<PlayConditinoResponse>(mRootView) {
                    @Override
                    public void onSuccess(PlayConditinoResponse response) {
                        mRootView.setConditionData(response);

                    }
                })
        );
    }
}
